module sdldee.c.sdl;

private import std.c.stdio;

// This file imports all function in SDL 1.2.11

// SDL.h
extern (C) int SDL_Init(uint flags);
extern (C) int SDL_InitSubSystem(uint flags);
extern (C) void SDL_QuitSubSystem(uint flags);
extern (C) uint SDL_WasInit(uint flags);
extern (C) void SDL_Quit();

// SDL_active.h
extern (C) ubyte SDL_GetAppState();

// SDL_audio.h
struct SDL_AudioSpec {
	int freq;
	ushort format;
	ubyte channels;
	ubyte silence;
	ushort samples;
	ushort padding;
	uint size;
	void* function(void* userdata, ubyte* stream, int len) callback;
	void* userdata;
}

struct SDL_AudioCVT {
	int needed;
	ushort src_format;
	ushort dst_format;
	double rate_incr;
	ubyte* buf;
	int len;
	int len_cvt;
	int len_mult;
	double len_ratio;
	void*[] filters(SDL_AudioCVT* cvt, ushort format);
	int filter_index;
}

extern (C) int SDL_AudioInit(char* driver_name);
extern (C) void SDL_AudioQuit();
extern (C) char* SDL_AudioDriverName(char* namebuf, int maxlen);
extern (C) int SDL_OpenAudio(SDL_AudioSpec* desired, SDL_AudioSpec* obtained);
extern (C) int SDL_GetAudioStatus();
extern (C) void SDL_PauseAudio(int pause_on);
extern (C) SDL_AudioSpec* SDL_LoadWAV_RW(SDL_RWops* src, int freesrc, SDL_AudioSpec* spec, ubyte** audio_buf, uint* audio_len);

SDL_AudioSpec* SDL_LoadWAV(char* file, SDL_AudioSpec* spec, ubyte** audio_buf, uint* audio_len) {
	return SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1, spec, audio_buf, audio_len);
}

extern (C) void SDL_FreeWAV(ubyte* audio_buf);
extern (C) int SDL_BuildAudioCVT(SDL_AudioCVT* cvt, ushort src_format, ubyte src_channels, int src_rate, ushort dst_format, ubyte dst_channels, int dst_rate);
extern (C) int SDL_ConvertAudio(SDL_AudioCVT* cvt);
extern (C) void SDL_MixAudio(ubyte* dst, ubyte* src, uint len, int volume);
extern (C) void SDL_LockAudio();
extern (C) void SDL_UnlockAudio();
extern (C) void SDL_CloseAudio();

// SDL_cdrom.h
extern (C) int CD_INDRIVE(int status) {
	return status > 0;
}

struct SDL_CDtrack {
	ubyte id;
	ubyte type;
	ushort unused;
	uint length;
	uint offset;
}

struct SDL_CD {
	int id;
	int status;
	int numtracks;
	int cur_track;
	int cur_frame;
	SDL_CDtrack track[100];
}

void FRAMES_TO_MSF(int f, int* M, int* S, int* F) {
	int value = f;
	*F = value % 75;
	value /= 75;
	*S = value % 60;
	value /= 60;
	*M = value;
}

int MSF_TO_FRAMES(int M, int S, int F) {
	return (M * 60 * 75) + (S * 75) + F;
}

extern (C) int SDL_CDNumDrives();
extern (C) char* SDL_CDName(int drive);
extern (C) SDL_CD* SDL_CDOpen(int drive);
extern (C) int SDL_CDStatus(SDL_CD* cdrom);
extern (C) int SDL_CDPlayTracks(SDL_CD* cdrom, int start_track, int start_frame, int ntracks, int nframes);
extern (C) int SDL_CDPlay(SDL_CD* cdrom, int start, int length);
extern (C) int SDL_CDPause(SDL_CD* cdrom);
extern (C) int SDL_CDResume(SDL_CD* cdrom);
extern (C) int SDL_CDStop(SDL_CD* cdrom);
extern (C) int SDL_CDEject(SDL_CD* cdrom);
extern (C) void SDL_CDClose(SDL_CD* cdrom);

// SDL_cpuinfo.h
extern int SDL_HasRDTSC();
extern int SDL_HasMMX();
extern int SDL_HasMMXExt();
extern int SDL_Has3DNow();
extern int SDL_Has3DNowExt();
extern int SDL_HasSSE();
extern int SDL_HasSSE2();
extern int SDL_HasAltiVec();

// SDL_error.h
extern (C) void SDL_SetError(char* fmt, ...);
extern (C) char* SDL_GetError();
extern (C) void SDL_ClearError();
extern (C) void SDL_Error(int code);

// SDL_events.h
int SDL_EVENTMASK(int X) {
	return 1 << X;
}

struct SDL_ActiveEvent {
	ubyte type;
	ubyte gain;
	ubyte state;
}

struct SDL_KeyboardEvent {
	ubyte type;
	ubyte which;
	ubyte state;
	SDL_keysym keysym;
}

struct SDL_MouseMotionEvent {
	ubyte type;
	ubyte which;
	ubyte state;
	ushort x, y;
	short xrel;
	short yrel;
}

struct SDL_MouseButtonEvent {
	ubyte type;
	ubyte which;
	ubyte button;
	ubyte state;
	ushort x, y;
}

struct SDL_JoyAxisEvent {
	ubyte type;
	ubyte which;
	ubyte axis;
	short value;
}

struct SDL_JoyBallEvent {
	ubyte type;
	ubyte which;
	ubyte ball;
	short xrel;
	short yrel;
}

struct SDL_JoyHatEvent {
	ubyte type;
	ubyte which;
	ubyte hat;
	ubyte value;
}

struct SDL_JoyButtonEvent {
	ubyte type;
	ubyte which;
	ubyte button;
	ubyte state;
}

struct SDL_ResizeEvent {
	ubyte type;
	int w;
	int h;
}

struct SDL_ExposeEvent {
	ubyte type;
}

struct SDL_QuitEvent {
	ubyte type;
}

struct SDL_UserEvent {
	ubyte type;
	int code;
	void* data1;
	void* data2;
}

struct SDL_SysWMEvent {
	ubyte type;
	SDL_SysWMmsg *msg;
}

union SDL_Event {
	ubyte type;
	SDL_ActiveEvent active;
	SDL_KeyboardEvent key;
	SDL_MouseMotionEvent motion;
	SDL_MouseButtonEvent button;
	SDL_JoyAxisEvent jaxis;
	SDL_JoyBallEvent jball;
	SDL_JoyHatEvent jhat;
	SDL_JoyButtonEvent jbutton;
	SDL_ResizeEvent resize;
	SDL_ExposeEvent expose;
	SDL_QuitEvent quit;
	SDL_UserEvent user;
	SDL_SysWMEvent syswm;
}

extern (C) void SDL_PumpEvents();

enum SDL_eventaction {
	SDL_ADDEVENT,
	SDL_PEEKEVENT,
	SDL_GETEVENT
}

extern (C) int SDL_PeepEvents(SDL_Event* events, int numevents, SDL_eventaction action, uint mask);
extern (C) int SDL_PollEvent(SDL_Event* event);
extern (C) int SDL_WaitEvent(SDL_Event* event);
extern (C) int SDL_PushEvent(SDL_Event* event);
typedef SDL_EventFilter int function(SDL_Event* event);
extern (C) void SDL_SetEventFilter(SDL_EventFilter filter);
extern (C) SDL_EventFilter SDL_GetEventFilter();
extern (C) ubyte SDLCALL SDL_EventState(Uint8 type, int state);

// SDL_joystick.h
struct SDL_Joystick {}
extern (C) int SDL_NumJoysticks();
extern (C) char* SDL_JoystickName(int device_index);
extern (C) SDL_Joystick* SDL_JoystickOpen(int device_index);
extern (C) int SDL_JoystickOpened(int device_index);
extern (C) int SDL_JoystickIndex(SDL_Joystick* joystick);
extern (C) int SDL_JoystickNumAxes(SDL_Joystick* joystick);
extern (C) int SDL_JoystickNumBalls(SDL_Joystick* joystick);
extern (C) int SDL_JoystickNumHats(SDL_Joystick* joystick);
extern (C) int SDL_JoystickNumButtons(SDL_Joystick* joystick);
extern (C) void SDL_JoystickUpdate();
extern (C) int SDL_JoystickEventState(int state);
extern (C) short SDL_JoystickGetAxis(SDL_Joystick* joystick, int axis);
extern (C) ubyte SDL_JoystickGetHat(SDL_Joystick* joystick, int hat);
extern (C) int SDL_JoystickGetBall(SDL_Joystick* joystick, int ball, int* dx, int* dy);
extern (C) ubyte SDL_JoystickGetButton(SDL_Joystick* joystick, int button);
extern (C) void SDL_JoystickClose(SDL_Joystick* joystick);

// SDL_keyboard.h
struct SDL_keysym {
	ubyte scancode;
	SDLKey sym;
	SDLMod mod;
	Uint16 unicode;
}

extern (C) int SDL_EnableUNICODE(int enable);
extern (C) int SDL_EnableKeyRepeat(int delay, int interval);
extern (C) void SDL_GetKeyRepeat(int* delay, int* interval);
extern (C) ubyte* SDL_GetKeyState(int* numkeys);
extern (C) SDLMod SDL_GetModState();
extern (C) void SDL_SetModState(SDLMod modstate);
extern (C) char* SDL_GetKeyName(SDLKey key);

// SDL_loadso.h
extern (C) void* SDL_LoadObject(char *sofile);
extern (C) void* SDL_LoadFunction(void *handle, char *name);
extern (C) void SDL_UnloadObject(void *handle);

// SDL_main.h

// SDL_mouse.h
struct WMcursor {}
struct SDL_Cursor {
	SDL_Rect area;
	short hot_x, hot_y;
	ubyte* data;
	ubyte* mask;
	ubyte* save[2];
	WMcursor* wm_cursor;
}

extern (C) ubyte SDL_GetMouseState(int* x, int* y);
extern (C) ubyte SDL_GetRelativeMouseState(int* x, int* y);
extern (C) void SDL_WarpMouse(ushort x, ushort y);
extern (C) SDL_Cursor* SDL_CreateCursor(ubyte* data, ubyte* mask, int w, int h, int hot_x, int hot_y);
extern (C) void SDL_SetCursor(SDL_Cursor* cursor);
extern (C) SDL_Cursor* SDL_GetCursor(void);
extern (C) void SDL_FreeCursor(SDL_Cursor* cursor);
extern (C) int SDL_ShowCursor(int toggle);

int SDL_BUTTON(int X) {
	return 1 << (X - 1);
}

// SDL_mutex.h
struct SDL_mutex {}
extern (C) SDL_mutex* SDL_CreateMutex();

int SDL_LockMutex(SDL_mutex* m) {
	return SDL_mutexP(m);
}

extern (C) int SDL_mutexP(SDL_mutex* mutex);

int SDL_UnlockMutex(SDL_mutex* m) {
	return SDL_mutexV(m);
}

extern (C) int SDL_mutexV(SDL_mutex* mutex);
extern (C) void SDL_DestroyMutex(SDL_mutex* mutex);
struct SDL_sem {}
extern (C) SDL_sem* SDL_CreateSemaphore(uint initial_value);
extern (C) void SDL_DestroySemaphore(SDL_sem* sem);
extern (C) int SDL_SemWait(SDL_sem* sem);
extern (C) int SDL_SemTryWait(SDL_sem* sem);
extern (C) int SDL_SemWaitTimeout(SDL_sem* sem, uint ms);
extern (C) int SDL_SemPost(SDL_sem* sem);
extern (C) uint SDL_SemValue(SDL_sem* sem);
struct SDL_cond{};
extern (C) SDL_cond* SDL_CreateCond();
extern (C) void SDL_DestroyCond(SDL_cond* cond);
extern (C) int SDL_CondSignal(SDL_cond* cond);
extern (C) int SDL_CondBroadcast(SDL_cond* cond);
extern (C) int SDL_CondWait(SDL_cond* cond, SDL_mutex* mut);
extern (C) int SDL_CondWaitTimeout(SDL_cond* cond, SDL_mutex* mutex, uint ms);

// SDL_name.h

// SDL_opengl.h

// SDL_platform.h

// SDL_quit.h

// SDL_rwops.h
struct SDL_RWops {
	int function(SDL_RWops* context, int offset, int whence) seek;
	int function(SDL_RWops* context, void* ptr, int size, int maxnum) read;
	int function(SDL_RWops* context, void *ptr, int size, int num) write;
	int function(SDL_RWops* context) close;
	uint type;
	union hidden {
		version(Windows) {
			struct Win32io {
				int append;
				void* h;
			}
			Win32io win32io;
		}
		struct S {
			int autoclose;
			FILE* fp;
		}
		S s;
		struct Mem {
			ubyte* base;
			ubyte* here;
			ubyte* stop;
		}
		Mem mem;
		struct Unknown {
			void* data1;
		}
		Unknown unknown;
	}	
}

extern (C) SDL_RWops* SDL_RWFromFile(char* file, char* mode);
extern (C) SDL_RWops* SDL_RWFromFP(FILE* fp, int autoclose);
extern (C) SDL_RWops* SDL_RWFromMem(void* mem, int size);
extern (C) SDL_RWops* SDL_RWFromConstMem(void* mem, int size);
extern (C) SDL_RWops* SDL_AllocRW();
extern (C) void SDL_FreeRW(SDL_RWops* area);

int SDL_RWseek(SDL_RWops* ctx, int offset, int whence) {
	return ctx->seek(ctx, offset, whence);
}

int SDL_RWtell(SDL_RWops* ctx) {
	return ctx->seek(ctx, 0, 1);
}

int SDL_RWread(SDL_RWops* ctx, void* ptr, int size, int n) {
	return ctx->read(ctx, ptr, size, n);
}

int SDL_RWwrite(SDL_RWops* ctx, void* ptr, int size, int n) {
	return ctx->write(ctx, ptr, size, n);
}

int SDL_RWclose(SDL_RWops* ctx) {
	return ctx->close(ctx);
}

extern (C) ushort SDL_ReadLE16(SDL_RWops* src);
extern (C) ushort SDL_ReadBE16(SDL_RWops* src);
extern (C) uint SDL_ReadLE32(SDL_RWops* src);
extern (C) uint SDL_ReadBE32(SDL_RWops* src);
extern (C) ulong SDL_ReadLE64(SDL_RWops* src);
extern (C) ulong SDL_ReadBE64(SDL_RWops* src);
extern (C) int SDL_WriteLE16(SDL_RWops* dst, ushort value);
extern (C) int SDL_WriteBE16(SDL_RWops* dst, ushort value);
extern (C) int SDL_WriteLE32(SDL_RWops* dst, uint value);
extern (C) int SDL_WriteBE32(SDL_RWops* dst, uint value);
extern (C) int SDL_WriteLE64(SDL_RWops* dst, ulong value);
extern (C) int SDL_WriteBE64(SDL_RWops* dst, ulong value);

// SDL_syswm.h

// SDL_thread.h

// SDL_timer.h
extern (C) uint SDL_GetTicks();
extern (C) void SDL_Delay(uint ms);
typedef uint function(uint interval) SDL_TimerCallback;
extern (C) int SDL_SetTimer(uint interval, SDL_TimerCallback callback);
typedef
typedef Uint32(SDLCALL *SDL_NewTimerCallback)(Uint32 interval, void *param);


// SDL_video.h
struct SDL_Rect {
	short x, y;
	ushort w, h;
}

struct SDL_Color {
	ubyte r;
	ubyte g;
	ubyte b;
	ubyte unused;
}

struct SDL_Palette {
	int ncolors;
	SDL_Color* colors;
}

struct SDL_PixelFormat {
	SDL_Palette* palette;
	ubyte BitsPerPixel;
	ubyte BytesPerPixel;
	ubyte Rloss, Gloss, Bloss, Aloss;
	ubyte Rshift, Gshift, Bshift, Ashift;
	uint Rmask, Gmask, Bmask, Amask;
	uint colorkey;
	ubyte alpha;
}

struct SDL_Surface {
	uint flags;
	SDL_PixelFormat* format;
	int w, h;
	ushort pitch;
	void* pixels;
	int offset;
	void* hwdata;
	SDL_Rect clip_rect;
	uint unused1;
	uint locked;
	void* map;
	uint format_version;
	int refcount;
}

struct SDL_VideoInfo {
	ubyte available;
	ubyte blit;
	ushort unused;
	uint video_mem;
	SDL_PixelFormat* vfmt;
	int current_w;
	int current_h;
}

struct SDL_Overlay {
	uint format;
	int w, h;
	int planes;
	ushort *pitches;
	ubyte **pixels;
	void* hwfuncs;
	void* hwdata;
	uint flags;
}

extern (C) int SDL_VideoInit(char* driver_name, uint flags);
extern (C) void SDL_VideoQuit();
extern (C) char* SDL_VideoDriverName(char* namebuf, int maxlen);
extern (C) SDL_Surface* SDL_GetVideoSurface();
extern (C) SDL_VideoInfo* SDL_GetVideoInfo();
extern (C) int SDL_VideoModeOK(int width, int height, int bpp, uint flags);
extern (C) SDL_Rect** SDL_ListModes(SDL_PixelFormat* format, uint flags);
extern (C) SDL_Surface* SDL_SetVideoMode(int width, int height, int bpp, uint flags);
extern (C) void SDL_UpdateRects(SDL_Surface* screen, int numrects, SDL_Rect* rects);
extern (C) void SDL_UpdateRect(SDL_Surface* screen, int x, int y, int w, int h);
extern (C) int SDL_Flip(SDL_Surface* screen);
extern (C) int SDL_SetGamma(float red, float green, float blue);
extern (C) int SDL_SetGammaRamp(ushort* red, ushort* green, ushort* blue);
extern (C) int SDL_GetGammaRamp(ushort* red, ushort* green, ushort* blue);
extern (C) int SDL_SetColors(SDL_Surface* surface, SDL_Color* colors, int firstcolor, int ncolors);
extern (C) int SDL_SetPalette(SDL_Surface* surface, int flags, SDL_Color* colors, int firstcolor, int ncolors);
extern (C) uint SDL_MapRGB(SDL_PixelFormat* format, ubyte r, ubyte g, ubyte b);
extern (C) uint SDL_MapRGBA(SDL_PixelFormat* format, ubyte r, ubyte g, ubyte b, ubyte a);
extern (C) void SDL_GetRGB(uint pixel, SDL_PixelFormat* fmt, ubyte* r, ubyte* g, ubyte* b);
extern (C) void SDL_GetRGBA(uint pixel, SDL_PixelFormat* fmt, ubyte* r, ubyte* g, ubyte* b, ubyte* a);
extern (C) SDL_Surface* SDL_CreateRGBSurface(uint flags, int width, int height, int depth, uint Rmask, uint Gmask, uint Bmask, uint Amask);
extern (C) SDL_Surface* SDL_CreateRGBSurfaceFrom(void* pixels, int width, int height, int depth, int pitch, uint Rmask, uint Gmask, uint Bmask, uint Amask);
extern (C) void SDL_FreeSurface(SDL_Surface* surface);
extern (C) int SDL_LockSurface(SDL_Surface* surface);
extern (C) void SDL_UnlockSurface(SDL_Surface* surface);
extern (C) SDL_Surface* SDL_LoadBMP_RW(SDL_RWops* src, int freesrc);
extern (C) int SDL_SaveBMP_RW(SDL_Surface* surface, SDL_RWops* dst, int freedst);
extern (C) int SDL_SetColorKey(SDL_Surface* surface, uint flag, uint key);
extern (C) int SDL_SetAlpha(SDL_Surface* surface, uint flag, ubyte alpha);
extern (C) int SDL_SetClipRect(SDL_Surface* surface, SDL_Rect* rect);
extern (C) void SDL_GetClipRect(SDL_Surface* surface, SDL_Rect* rect);
extern (C) SDL_Surface* SDL_ConvertSurface(SDL_Surface* src, SDL_PixelFormat* fmt, uint flags);
extern (C) int SDL_UpperBlit(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
extern (C) int SDL_LowerBlit(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
extern (C) int SDL_FillRect(SDL_Surface* dst, SDL_Rect* dstrect, uint color);
extern (C) SDL_Surface* SDL_DisplayFormat(SDL_Surface* surface);
extern (C) SDL_Surface* SDL_DisplayFormatAlpha(SDL_Surface* surface);
extern (C) SDL_Overlay* SDL_CreateYUVOverlay(int width, int height, uint format, SDL_Surface* display);
extern (C) int SDL_LockYUVOverlay(SDL_Overlay* overlay);
extern (C) void SDL_UnlockYUVOverlay(SDL_Overlay* overlay);
extern (C) int SDL_DisplayYUVOverlay(SDL_Overlay* overlay, SDL_Rect* dstrect);
extern (C) void SDL_FreeYUVOverlay(SDL_Overlay* overlay);
extern (C) int SDL_GL_LoadLibrary(char* path);
extern (C) void* SDL_GL_GetProcAddress(char* proc);
extern (C) int SDL_GL_SetAttribute(int attr, int value);
extern (C) int SDL_GL_GetAttribute(int attr, int* value);
extern (C) void SDL_GL_SwapBuffers();
extern (C) void SDL_GL_UpdateRects(int numrects, SDL_Rect* rects);
extern (C) void SDL_GL_Lock();
extern (C) void SDL_GL_Unlock();
extern (C) void SDL_WM_SetCaption(char* title, char* icon);
extern (C) void SDL_WM_GetCaption(char** title, char** icon);
extern (C) void SDL_WM_SetIcon(SDL_Surface* icon, ubyte* mask);
extern (C) int SDL_WM_IconifyWindow();
extern (C) int SDL_WM_ToggleFullScreen(SDL_Surface* surface);
extern (C) int SDL_WM_GrabInput(int mode);

